﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pibby.Core
{
	public enum ProgressEventStatus
	{
		Unknown,
		Starting,
		InProgress,
		Complete,
		Error
	}

	/// <summary>
	/// Used to measure progress
	/// </summary>
	public class ProgressEventArgs : System.EventArgs
	{
		public ProgressEventArgs()
			: this(0)
		{
		}

		public ProgressEventArgs(int percent)
			: this(percent, 100, ProgressEventStatus.InProgress, null)
		{
		}

		public ProgressEventArgs(long current, long total, ProgressEventStatus status, object tag)
			: this(current, total, status, tag, string.Empty)
		{
		}

		public ProgressEventArgs(long current, long total, ProgressEventStatus status, object tag, string message)
		{
			current = Math.Max(current, 0);
			current = Math.Min(current, total);

			this.CurrentProgress = current;
			this.Status = status;
			this.Maximum = total;

			this.Tag = tag;
			this.Message = message;
		}

		public int PercentComplete
		{
			get
			{
				return (int)((this.CurrentProgress * 100) / this.Maximum);
			}
		}

		public long CurrentProgress
		{
			get;
			private set;
		}

		public long Maximum
		{
			get;
			private set;
		}

		public ProgressEventStatus Status
		{
			get;
			private set;
		}

		public object Tag
		{
			get;
			private set;
		}

		public string Message
		{
			get;
			private set;
		}
	}
}
